home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / FLSEEK.C < prev    next >
Text File  |  1990-08-09  |  2KB  |  65 lines

  1. /**
  2. *
  3. *  Name         flseek -- Position the file pointer
  4. *
  5. *  Synopsis     ercode = flseek(handle,mov,ppos);
  6. *               int  ercode       DOS error return code
  7. *               int  handle       Handle of file to be positioned
  8. *               int  mov          Positioning technique
  9. *               long *ppos        File position
  10. *
  11. *  Description  Each handle has a file position pointer associated with it.
  12. *               FLSEEK moves the pointer using the technique specified in
  13. *               mov.  The possibilities are:
  14. *
  15. *               0 - Absolute.  Move the pointer to the offset specified
  16. *                   in pos from the beginning of the file.
  17. *               1 - Relative.  Move the pointer to the offset from the
  18. *                   current file position.
  19. *               2 - End of File.  Move the pointer to the offset from
  20. *                   the end of the file.
  21. *
  22. *               Upon input, ppos contains the offset in bytes to move
  23. *               the file pointer, and upon return, the new file pointer
  24. *               location.  The function FLREAD and FLWRITE also alter
  25. *               the file pointer position.
  26. *
  27. *  Returns      ercode            DOS 2.0 function error return code
  28. *               ppos              The file pointer position after the seek
  29. *                                 has been accomplished.  If an error is
  30. *                                 encountered, the position is set to -1.
  31. *
  32. *  Version      1.0  (C)Copyright Blaise Computing Inc.  1983
  33. *
  34. **/
  35. #define utbyword(a,b)   (((a)<<8)|((b)&0x00ff))  /* a is high, b low   */
  36.  
  37. struct dreg
  38. {
  39.   unsigned ax,bx,cx,dx,si,di,ds,es;
  40. };
  41. #define DOSREG  struct dreg
  42.  
  43. int flseek(handle,mov,ppos)
  44. int  handle,mov;
  45. long *ppos;
  46. {
  47.  
  48.     DOSREG dos_reg;
  49.     int    ercode,utinit(),dos();
  50.  
  51.     utinit(&dos_reg);                  /* Initialize registers         */
  52.     dos_reg.ax = utbyword(0x42,mov);   /* Function call 42             */
  53.     dos_reg.bx = handle;
  54.     dos_reg.cx = (unsigned)((*ppos >> 16) & 0xffff);  /* High order and*/
  55.     dos_reg.dx = (unsigned)(*ppos & 0xffff);       /* low order word   */
  56.     ercode     = dos(&dos_reg);
  57.     if (ercode == 0)
  58.        *ppos = ((long)(dos_reg.dx) << 16) + (long)dos_reg.ax;
  59.     else
  60.        *ppos = -1;
  61.  
  62.     return(ercode);
  63.  
  64. }
  65.